<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>变量的解构赋值</title>
</head>
<body>
<script>
  {
    let [a,b,c] = [0,1,2];
    console.log("a-",a,"b-",b,"c-",c);
    let [foo = "true"] = [];
    console.log("foo",foo);

    let [k,j=`Gu`,h] = ["Mr",,"H呢？"];
    console.log(k,"+",j,"+",h)
  }
  {
    let {foo,bar} = {foo:'MrGu', bar:'熊猫'}
    console.log(foo,"+",bar);
  }
  {
    let {foo,bar=`MrsHunag`} = {foo:'MrGu', bar: undefined}
    console.log(foo,"+",bar);
  }
  {
    let foo;
    ({foo} = {foo:'nihao'}); // 先赋值，再进行解构，必须在解构外面加（）才能成功
    console.log("foo---",foo);
  }

  {
    const [a,b,c,d,e,f,g] = 'JsStudy'; // 尽量使用单引号
    console.log(a,'+',b,'+',c,'+',d,'+',e,'+',f,'+',g)
  }
</script>

</body>
</html>